All Questions
Tagged with text-formattingprintf
21 questions
1vote
2answers
449views
shortcut command for printf with a specific format string
I want to use a shortcut command for printf with a specific format string, and came up with the following. local PF="printf %s\n" $PF "Some Text" It does the job, but wonder if ...
1vote
3answers
1kviews
Center text with printf
printf "%*s\n" $(((${#fname}+$COLUMNS)/2)) "$fname" I get this error: line 9: (7+)/2: syntax error: operand expected (error token is ")/2") This works in the terminal ...
2votes
2answers
680views
Best way to pad stdin to desired length with NULL
I have the following requirement. I have an input stream that I need to truncate to a certain fixed length of bytes. I do not know the length of the input stream beforehand. If the stream is less in ...
31votes
3answers
79kviews
How to do formatted printing with jq?
jq has built-in ability to convert numbers to string or concatenate strings. How can I format strings inside jq similar to printf like padding (%4s). For example, how can I force number to occupy 10 ...
0votes
2answers
891views
set format with printf for $0
I compute the row average of the following data set however I have trouble setting the correct format for $0 so as to produce the file-output presented below. I currently have: awk '{T=0; for (i=1;i&...
0votes
3answers
3kviews
Inserting text with formatting at the start of a file with printf
I need to append something with particular formatting at the start of a text file. I have looked into How do I append text to the beginning and end of multiple text files in Bash, but not sure how to ...
0votes
2answers
416views
align text bash script
I'm writing a script that will check the many applications services. I have the script looping through the services. Just looking for the best way to align the output text. Here is the code: ...
11votes
4answers
2kviews
Modify width of first column in file with a variable number of fields, using awk
I understand how to use awk's printf function, but I don't want to specify every field. For example, assume this is my file: c1|c2|c3|c4|c5 c6|c7|c8|c9|c10 c11|c12|c13|c14|c15 I want to format it so ...
1vote
1answer
1kviews
how to print hyphen in double quotes along with other strings
cat inv_summary_1.txt | while read -r aLine do F1=`echo "$aLine" | cut -d "," -f1` F2=`echo "$aLine" | cut -d "," -f2` echo " 0 RUN_ID STR [0] \"${F2}\" " done 191245204696,REG-...
2votes
3answers
1kviews
How to reverse input order?
The following code provides a backwards output when inputted as first to last, so input is required to be in reverse. How can this be flipped/reversed? EDITED on 2019-05-23_07:52:04 (printf 'g?%s?m0\...
0votes
2answers
628views
How to modify this `printf` code to reverse it's action?
Code below can, for example ... [anony@mous-pc ~]$ (printf 'g?%s?m0\n' 008 006 004 002 ; printf 'wq\n') | ed -s file.txt ... take all of numbers within ... [anony@mous-pc ~]$ cat some.txt 005 003 ...
1vote
3answers
629views
print a column with the desire format output [closed]
I have a list of the following data in a file: -0.3476890000000000 0.0743938333333333 -1.0990240000000000 0.0743938333333333 -0.2169100000000000 0.0879397500000000 and I am ...
1vote
2answers
58views
Reconsider spacing of columns
I have a file with the following format 1 1 1 0.02484183 57.2400000 24.6000000 2 1 2 -0.16091000 56.5200000 24.5600000 3 1 1 0.02484183 55.5700000 24....
0votes
3answers
72views
Aligning the third word with 20 spaces from the beginning of the second word [duplicate]
We have the following file: cat info.txt linux03.sys98.com net16777728 Speed: 1000Mb/s linux03.sys98.com net16777728 Speed: 1000Mb/s linux01.sys98.com net3f0 Speed: 1000Mb/s ...
0votes
1answer
1kviews
Bash printf formatting not working!
My script is: #!/bin/bash num1=32.55 num2=145.958 printf "%5.2f\n" $num1 printf "%5.2f\n" $num2 The output is: 32.55 145.96 Instead of: 32.55 145.96 What's going on? If it's any help, I'm ...